Repository navigation
fix(jobs): give job-run Jobs an id label and a bounded TTL (closes #634) - #639
Conversation
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Deploying styrmin with
|
| Latest commit: |
45d05fe
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fa1a21b4.styrmin.pages.dev |
| Branch Preview URL: | https://ai-bug-pipeline-634-job-leak.styrmin.pages.dev |
|
Verdict: ApprovedRealism
CorrectnessThe test calls the production
I confirmed against the current QualityPure unit test, no I/O, no mocks needed, colocated with the 8 existing tests for this module and reusing the existing AlignmentMatches the analyst's root cause precisely: fix scoped to CI signal
Add this agentic workflow to your repoTo install this agentic workflow, run |
|
/bug-fix |
_build_job_manifest built the runJob mutation's Job with no ttlSecondsAfterFinished and no Styrmin id label, so Kubernetes never garbage-collected it and nothing else in the codebase deleted it either. Every runJob call therefore permanently left one more Job and its pod in the deployment's namespace, and the Job could not be selected by a Styrmin record id label per ADR-073. Add a styrmin.io/task-id label (plus app.kubernetes.io/managed-by) and a ttlSecondsAfterFinished to the manifest so the Job is findable by id and Kubernetes removes it a bounded time after it finishes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Commit pushed:
|
|
Verdict: ApprovedCorrectnessThe fix is scoped exactly to
Code quality
Documentation alignmentNo ADR/guide describes per-field TTL/label specifics for this Job, and this is an internal manifest-construction detail, not a user-visible CLI/SDK/GraphQL/driver-format change, so no doc update is required here. A towncrier fragment ( Test integrityConfirmed unchanged — see above. CI signalThe authoritative
Add this agentic workflow to your repoTo install this agentic workflow, run |
…or a test run Reinstalled from opsmill/opsmill-cicd-workflows@fix/bug-pipeline-marker-reads (opsmill/opsmill-cicd-workflows#67) to run the reviewer once on #639. Repoint to @main after #66 and #67 merge. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Analyst's findings (summary)
Replication test
Test file:
backend/tests/unit/agent/tasks/test_run_job_flows.pyTest name:
test_build_job_manifest_is_findable_by_id_and_bounded_in_lifetimeWhat it tests: calls the production
_build_job_manifestfunction directly (the same manifest builderrun_job_commanduses to create the Job viarun_kubernetes_job) and asserts the resulting manifest carries (a) ametadata.labelsentry whose value is the task's id, so the Job is selectable by id per ADR-073, and (b) a positive integerspec.ttlSecondsAfterFinished, so Kubernetes garbage-collects the Job instead of it accumulating forever.Local run (evidence)
The other 8 pre-existing tests in the file still pass unchanged, confirming the new test is the only one exercising the missing behavior.
Expected CI signal: the
Unit Testscheck should FAIL on this PR, for this reason:_build_job_manifestcurrently emits a manifest with nometadata.labelskey at all and nospec.ttlSecondsAfterFinished, which is exactly the root cause of the Job/pod leak described in #634.Test expectations
The test asserts the mechanism, not an exact TTL value (the issue states the retention duration is "Not decided yet"):
manifest["metadata"]["labels"]exists and contains the task's id as one of its values (an id label the Job can be found by, per ADR-073), rather than relying only on thegenerateName: job-run-<task_id>-prefix.manifest["spec"]["ttlSecondsAfterFinished"]is present and is a positive integer, so Kubernetes removes the Job (and its pod) after it finishes instead of it accumulating indefinitely.It deliberately does not assert a specific TTL number, a specific label key, or touch
run_kubernetes_job/_delete_earlier_job— per the analyst's note, the fix belongs in_build_job_manifestalone and the exact TTL is a separate product decision.AGENT_TEST_COMPLETEAdd this agentic workflow to your repo
To install this agentic workflow, run
<!-- This is an auto-generated description by cubic. -->
<a href="(cubic.dev/redacted) target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="(www.cubic.dev/redacted)<source media="(prefers-color-scheme: light)" srcset="(www.cubic.dev/redacted)<img alt="View guided diff" src="(www.cubic.dev/redacted)</picture></a> <a href="(www.cubic.dev/redacted) target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="(www.cubic.dev/redacted)<source media="(prefers-color-scheme: light)" srcset="(www.cubic.dev/redacted)<img alt="Turn on auto-fix" src="(www.cubic.dev/redacted)</picture></a>
<!-- End of auto-generated description by cubic. -->
Fix strategy
Followed the analyst's root-cause and fix strategy as-is, scoped entirely to
_build_job_manifestinbackend/styrmin_backend/agent/tasks/orchestration.py:metadata.labelsblock to the Job manifest:app.kubernetes.io/managed-by: styrminandstyrmin.io/task-id: <task_id>(newTASK_ID_LABELconstant), so the Job is selectable by a Styrmin record id per ADR-073, not only by itsgenerateNameprefix.spec.ttlSecondsAfterFinished(new_JOB_FINISHED_TTL_SECONDS = 3600) so Kubernetes garbage-collects the Job (and its pod) a bounded time after it reachesComplete/Failed, instead of it accumulating forever.3600is a placeholder — flagged with a comment at the definition site — not a final product decision. Happy to adjust to whatever value the team settles on; it's a single constant._delete_earlier_job/ACTION_JOB_LABELor add an explicit delete call, per the analyst's explicit "Do NOT" guidance —ttlSecondsAfterFinishedis the Kubernetes-native mechanism and avoids a race with that function's unrelated same-name-replacement use case (fix(actions): execute_commands can run only once per deployment namespace (Job never cleaned up) #374)._expected_manifesthelper intest_run_job_flows.py(used bytest_run_job_command_runs_the_job_as_the_command_step, which asserts the full manifest by exact equality) to include the newlabelsandttlSecondsAfterFinishedkeys, since production output legitimately changed. The new replication test (test_build_job_manifest_is_findable_by_id_and_bounded_in_lifetime) itself was not modified.changelog/634.fixed.md).Local run (evidence)
Replication test, now passing:
Full test file (9/9 passed):
Affected unit suite (
backend/tests/unit/agent/, 762/762 passed):Full backend unit suite: 5012 passed, 6 skipped, 9 failed, 237 errors — all pre-existing and environmental (Docker daemon unavailable for
testcontainers-backed Postgres migration tests in this sandbox); none touchorchestration.py,run_job, or_build_job_manifest(confirmed against.pytest_cache/v/cache/lastfailed).uv run invoke format lint(backend ruff/ty, frontend eslint/prettier, GraphQL schema validation, codegen-freshness check): all green. No GraphQL schema or query files were touched, so noschema.graphql/ SDK regeneration was needed.AGENT_FIX_COMPLETEWarning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
telemetry.invalidTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run